package com.yanqu.road.server.cmd.activity.entername;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cross3.activity.EnterNameProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.entername.EnterNameActivityConfig;
import com.yanqu.road.server.manger.activity.entername.EnterNameActivityMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.Protocol;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = Protocol.S_ENTER_NAME_DISPERSE_GOLD_SYNC_FROM_CHANNEL, desc = "地区pk散财")
public class EnterNameDisperseGoldFromChannelCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage yanQuMessage) throws Exception {
        EnterNameProto.ChannelEnterNameDisperseGoldSyncMsg syncMsg = EnterNameProto.ChannelEnterNameDisperseGoldSyncMsg.parseFrom(yanQuMessage.getBytes());
        EnterNameActivityConfig config = EnterNameActivityMgr.getActivityConfig(syncMsg.getActivityId());
        if(config != null){
            for (long userId : syncMsg.getUserIdList()) {
                GamePlayer player = GamePlayerMgr.getOnlinePlayer(userId);
                if(player != null){
                    EnterNameProto.EnterNameDisperseGoldSyncMsg.Builder clientMsg = EnterNameProto.EnterNameDisperseGoldSyncMsg.newBuilder();
                    EnterNameProto.EnterNameDisperseGoldMsg.Builder builder = EnterNameProto.EnterNameDisperseGoldMsg.newBuilder();
                    builder.addAllPk(syncMsg.getPkList());
                    builder.setActivityId(syncMsg.getActivityId());
                    //builder.setActivityType()
                    //这边是一个；登录是多个一起下发
                    clientMsg.addDisGold(builder);
                    player.sendPacket(Protocol.U_ENTER_NAME_DISPERSE_GOLD_SYNC, clientMsg);
                }
            }
        }
    }
}
